package name.marz.to.go.ahg.core.executer;

import java.io.IOException;
import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;

import name.marz.to.go.ahg.common.util.LogUtil;
import name.marz.to.go.ahg.core.AutoGetterHttpClient;
import name.marz.to.go.ahg.core.responsehandler.DocumentResponseHandler;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.jsoup.nodes.Document;


public class DocumentGetExecuter extends AbstractExecuter<Document> {
	private static final Logger log = Logger.getLogger(DocumentGetExecuter.class.getName());
	
	public DocumentGetExecuter(URI uri, AutoGetterHttpClient client,String pageName) {
		super(uri, client, pageName);
	}
	public DocumentGetExecuter(URI uri, AutoGetterHttpClient client) {
		super(uri, client);
	}
	public DocumentGetExecuter(String uri, AutoGetterHttpClient client) {
		super(uri, client);
	}
	public DocumentGetExecuter(String uri, AutoGetterHttpClient client,String pageName) {
		super(uri, client, pageName);
	}

	@Override
	public Document execute() throws ClientProtocolException, IOException {
		// リクエスト生成
		HttpUriRequest req = new HttpGet(uri);
		
		// レスポンスハンドラ生成
		ResponseHandler<Document> handler = new DocumentResponseHandler(charset);
		//　リクエスト送信
		log.info(pageName+" ページ処理中 ... " + req.getURI());
		LogUtil.log(Level.FINE,req.getAllHeaders(),"request header");
		return client.execute(req, handler);
	}
}
